/*
 * File:   pwm.c
 * Author: powerlab
 *
 * Created on July 7, 2011, 3:38 PM
 */

#include "main.h"

void InitPWM()
{
    TRISB = 0;      // Configure PWM pin CCP1 as output
    CCP1CON = 0x0C;
    T2CON = 0;
    TMR2 = 0;
    T2CONbits.TMR2ON = 1;
}
void PWMDutyCycle(int ds)
{
    //CCP1CON = (CCP1CON & 0xCF) | ((ds << 4) & 0x30);
    //CCPR1L = ds >> 2;

    // PWM Resolution is 8 bits [ log(8000000/20000)/log(2) = 8.6 ] so use only the 8 bits in CCPR1L
    CCPR1L = ds;
}
/*
void PWMFrequency(int frequency)
{
    PR2 = ( 1 / (frequency * TCY * TMR2_PRE)) - 1;
}
*/




